import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class NetworkImageDisplay {
    public static void main(String[] args) {
        String imageUrl = "example.jpg";

        try {
            // Open a URL connection to the image URL
            URL url = new URL(imageUrl);
            // Read the image data from the URL
            BufferedImage image = ImageIO.read(url);

            if (image != null) {
                // Create a JFrame to display the image
                JFrame frame = new JFrame("Network Image Display");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                // Create a JLabel to hold the image
                JLabel label = new JLabel(new ImageIcon(image));

                // Add the label to the frame
                frame.getContentPane().add(label);

                // Pack the frame to fit the preferred size of its components
                frame.pack();

                // Center the frame on the screen
                frame.setLocationRelativeTo(null);

                // Make the frame visible
                frame.setVisible(true);
            } else {
                System.out.println("Failed to read image.");
            }
        } catch (IOException e) {
            System.err.println("Error reading image: " + e.getMessage());
        }
    }
}